Properly support optional location_type on submission form #922
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why
While working to make location optional when creating a
CommunityResource
, i ran into a bug in ourLocationForm
. Iflocation_type
is not selected on the front end, the form raises anInvalidInteractionError
, caused byrecord
filters not accepting an empty string value (location_type: ''
inparams
).I believe this should really be fixed upstream, but in the meantime, this PR implements a workaround.
Note that we weren't running into this on the Ask|Offer form because it doesn't allow
location_type
to be omitted; that form only shows the field once a user provides an address and then enlists the browser to ensure it's populated.What
active_interaction
to v4, to leverage improved form support. See the section titled 'Blank Values Treated As nil For Filters' in the release notesinteger
filter instead of arecord
filter, which correctly coerces''
to the default value (nil
).How
We can get away with not looking up the
LocationType
record ourselves and instead setting just the id on the location object. There's a tiny bit of logic required to align param names here because i didn't want to rename the param fromlocation_type
tolocation_type_id
all the way up the stack.Testing
submission_form_spec.rb
to simulatelocation_type: ''
.Next Steps
?
Outstanding Questions, Concerns and Other Notes
?
Pre-Merge Checklist